/************************************************************************

 This file is part of EscapeFromPrisonPlanet.

 EscapeFromPrisonPlanet is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 EscapeFromPrisonPlanet is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with Foobar.  If not, see <http://www.gnu.org/licenses/>.

************************************************************************/

// All code (c)2012 Scott Bevin. all rights reserved

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Media;

namespace LudumDare25Project
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class GameMain : Microsoft.Xna.Framework.Game
    {
        private GraphicsDeviceManager graphics;
        private GameScreenManager gsMgr;
        private SpriteBatch spriteBatch;

        private Song backgroundMusic;

        public GameMain()
        {
            graphics = new GraphicsDeviceManager(this);

            graphics.PreferredBackBufferWidth = 1000;
            graphics.PreferredBackBufferHeight = 600;
            graphics.ApplyChanges();

            Window.Title = "Escape From Prison Planet - Ludum Dare 25 - Scott Bevin, scott@gameXcore.co.uk, www.gameXcore.co.uk";

            //Window.AllowUserResizing = true;
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            gsMgr = new GameScreenManager(this);
            spriteBatch = new SpriteBatch(GraphicsDevice);

            Content.RootDirectory = "Content";

            this.IsMouseVisible = true;

            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            DebugDraw.Get = new DebugDraw(this.Content.Load<SpriteFont>("Fonts/DebugFont"));

            backgroundMusic = Content.Load<Song>("Music/BackgroundSynth1");
            MediaPlayer.Play(backgroundMusic);
            MediaPlayer.IsRepeating = true;

            SoundEffect.MasterVolume = 0.25f;

            //gsMgr.AddGameScreen(new GameScreens.GameplayScreen(), null, GameScreenManager.AddGameScreenData.PositioningOptions.OnTop);
            gsMgr.AddGameScreen(new GameScreens.IntroSplashScreen(), null, GameScreenManager.AddGameScreenData.PositioningOptions.OnTop);
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>s
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            gsMgr.Update((float)(gameTime.ElapsedGameTime.Milliseconds * 0.001f));
            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.White);
            gsMgr.Render((float)(gameTime.ElapsedGameTime.Milliseconds * 0.001f), this.GraphicsDevice);

            DebugDraw.Get.Render(spriteBatch);

            base.Draw(gameTime);
        }
    }
}